package com.itsm.xkitsm.liferoot.adapter;

import java.util.List;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;

import com.itsm.xkitsm.liferoot.R;
import com.itsm.xkitsm.liferoot.life.AddActivity;
import com.itsm.xkitsm.liferoot.life.weather.Execute_DB;
import com.itsm.xkitsm.liferoot.life.weather.Info_town;

public class MyExpandAdapter extends BaseExpandableListAdapter {
	private List<Object> data_town;
	private Context context;
	public static final int ItemHeight = 48;
	public static final int PaddingLeft = 38;
	private int myPaddingLeft = 0;
	private List<Object> data_city;
	private int groupId;
	private static String[][] arr_city;

	public MyExpandAdapter(List<Object> data_town, Context context) {
		super();
		this.data_town = data_town;
		this.context = context;
	}

	static public TextView getTextView(Context context) {
		AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT, ItemHeight);
		TextView textView = new TextView(context);
		textView.setLayoutParams(lp);
		textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
		return textView;
	}

	public static void updata(String[][] city) {
		arr_city = city;

	}

	public void clear_child() {
	}

	@Override
	public Object getChild(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return arr_city[arg0][arg1];
	}

	@Override
	public long getChildId(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return arg1;
	}

	@Override
	public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
			ViewGroup arg4) {
		// TODO Auto-generated method stub
		// LinearLayout ll = new LinearLayout(context);
		// ll.setOrientation(0);
		// TextView tv = new TextView(context);
		// tv.setText("     ");
		// tv.setTextSize(35);
		// ll.addView(tv);
		// View view = new View(context);
		// ImageView img = new ImageView(context);
		// img.setImageResource(R.drawable.ic_launcher);
		// ll.addView(img);
		// TextView textView = getTextView(this.context);
		// textView.setText(getChild(arg0, arg1).toString());
		// textView.setPadding(myPaddingLeft + PaddingLeft, 0, 0, 0);
		// ll.addView(textView);
		//
		// return ll;
		View view = LayoutInflater.from(context).inflate(
				R.layout.item_childview, null);
		TextView tv = (TextView) view.findViewById(R.id.tv_child);
		tv.setText(getChild(arg0, arg1).toString());
		return view;
	}

	@Override
	public int getChildrenCount(int arg0) {
		// TODO Auto-generated method stub
		return arr_city[arg0].length;
	}

	@Override
	public Object getGroup(int arg0) {
		// TODO Auto-generated method stub
		return ((Info_town) data_town.get(arg0)).getTown();
	}

	@Override
	public int getGroupCount() {
		// TODO Auto-generated method stub

		return data_town.size();
   
	}

	@Override
	public long getGroupId(int arg0) {
		groupId = arg0;
		return arg0;
	}

	@Override
	public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
		// TODO Auto-generated method stub
		// LinearLayout ll = new LinearLayout(context);
		// ll.setOrientation(0);
		// // ImageView img = new ImageView(context);
		// // img.setImageResource(R.drawable.ic_btn_speak_now);
		// // ll.addView(img);
		// TextView tv =new TextView(context);
		// tv.setText("                        ");
		// ll.addView(tv);
		//
		// TextView textView = getTextView(this.context);
		// textView.setText(getGroup(arg0).toString());
		// textView.setPadding(myPaddingLeft + (PaddingLeft >> 1), 0, 0, 0);
		// ll.addView(textView);
		// return ll;
		View view = LayoutInflater.from(context).inflate(
				R.layout.item_groupview, null);
		TextView tv = (TextView) view.findViewById(R.id.tv_group);
		tv.setText(getGroup(arg0).toString());
		return view;
	}

	@Override
	public boolean hasStableIds() {
		data_city = AddActivity.exe_db.query(
				((Info_town) data_town.get(groupId)).getTown(),
				Execute_DB.city_table);
		return true;
	}

	@Override
	public boolean isChildSelectable(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return true;
	}

}
